import { ajax, transformAjaxData } from '@jecloud/utils';
import { SYSTEM_PARAM_DEVICE } from '@/service/helper';
import * as urls from './urls';
/**
 * 账号登录
 * @param {Object} params
 * @param {String} params.account 账号
 * @param {String} params.password 密码
 * @param {String} params.deptId 部门ID
 * @param {String} params.code 三方登录临时授权码
 * @return {Promise}
 */
export function accountLoginApi(params) {
  const { account, password, deptId, code } = params;
  return ajax({
    url: urls.API_RBAC_LOGIN,
    params: { account, password, deptId, code, device: SYSTEM_PARAM_DEVICE },
    token: false,
  }).then(transformAjaxData);
}
/**
 * 动态密码登录
 * @param {Object} params
 * @param {String} params.phone 手机号
 * @param {String} params.captcha 验证码
 * @param {String} params.deptId 部门ID
 * @returns
 */
export function dynamicLoginApi(params) {
  const { phone, captcha, deptId } = params;
  return ajax({
    url: urls.API_RBAC_LOGIN_DYNAMIC,
    params: { phone, captcha, deptId, device: SYSTEM_PARAM_DEVICE },
    token: false,
  }).then(transformAjaxData);
}
/**
 * 发送验证码
 * @param {Object} params
 * @param {String} params.phone 手机号
 * @returns
 */
export function sendCaptchaApi(params) {
  const { phone } = params;
  return ajax({
    url: urls.API_RBAC_LOGIN_SEND_CAPTCHA,
    params: { phone, device: SYSTEM_PARAM_DEVICE },
    token: false,
  }).then(transformAjaxData);
}
/**
 * 校验验证码
 * @param {Object} params
 * @param {String} params.phone 手机号
 * @param {String} params.captcha 验证码
 * @returns
 */
export function checkCaptchaApi(params) {
  const { phone, captcha } = params;
  return ajax({
    url: urls.API_RBAC_LOGIN_CHECK_CAPTCHA,
    params: { phone, captcha, device: SYSTEM_PARAM_DEVICE },
    token: false,
    method: 'GET',
  }).then(transformAjaxData);
}

/**
 * 重置密码
 * @param {Object} params
 * @param {String} params.phone 手机号
 * @param {String} params.captcha 验证码
 * @param {String} params.newPassword 新密码
 * @param {String} params.confirmPassword 确认密码
 * @returns
 */
export function resetPasswordApi(params) {
  const { phone, captcha, newPassword, confirmPassword } = params;
  return ajax({
    url: urls.API_RBAC_LOGON_RESET_PASSWORD,
    params: { phone, captcha, newPassword, confirmPassword, device: SYSTEM_PARAM_DEVICE },
    token: false,
  }).then(transformAjaxData);
}
